package com.heima.article.feign;

import apis.article.IArticleClient;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.article.service.ApArticleConfigService;
import com.heima.article.service.ApArticleService;
import com.heima.model.article.dtos.ApArticleCommentDto;
import com.heima.model.article.dtos.ApArticleOpenCommentDto;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.article.pojos.ApArticle;
import com.heima.model.article.pojos.ApArticleConfig;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.search.vos.SearchArticleVo;
import com.heima.model.wemedia.dtos.CommentDto;
import com.heima.model.wemedia.dtos.CommentPageDto;
import com.heima.model.wemedia.dtos.ManageDto;
import com.heima.model.wemedia.dtos.CommentStatusManageDto;
import com.heima.model.wemedia.dtos.StatisticsDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

import java.util.Objects;

@RestController
@RequestMapping("/api/v1/article")
public class ArticleClient implements IArticleClient {
    @Autowired
    private ApArticleService apArticleService;
    @Autowired
    private ApArticleConfigService apArticleConfigService;

    @PostMapping("/save")
    public ResponseResult saveOrUpdateArticle(ArticleDto articleDto) {
        return apArticleService.saveOrUpdateArticle(articleDto);
    }


    @PostMapping("/api/v1/article")
    public ResponseResult<SearchArticleVo> selectESVoById(@RequestBody Long id) {
        return apArticleService.getESVoById(id);
    }

    /**
     * @param dto
     * @description: 查询上架的文章评论概览
     * @param:
     * @return: java.util.List<com.heima.model.wemedia.pojos.WmNews>
     * @author: liyong
     * @date: 2023/06/28 16:49
     */
    @PostMapping(value = "/pageCommentArticle")
    @Override
    public PageResponseResult pageCommentArticle(@RequestBody ManageDto dto) {

        return apArticleService.pageCommentArticle(dto);
    }

    /**
     * @param dto
     * @description: 修改评论开启关闭状态
     * @param: dto
     * @return: com.heima.model.common.dtos.ResponseResult
     * @author: liyong
     * @date: 2023/06/28 21:39
     */
    @Override
    @PostMapping("/updateStatus")
    public ResponseResult updateStatus(@RequestBody CommentDto dto) {
        System.out.println("dto = " + dto);
        return apArticleService.updateStatus(dto);
    }

    @PostMapping("/findNewsComment")
    public ResponseResult findArticleComment(@RequestBody ApArticleCommentDto apArticleCommentDto){
        return apArticleService.findArticleComment(apArticleCommentDto);
    }

    @PostMapping("/openComment")
    public ResponseResult openComment(ApArticleOpenCommentDto apArticleOpenCommentDto) {
        return apArticleService.openComment(apArticleOpenCommentDto);
    }

    @GetMapping("/api/v1/article/queryLikesAndConllections")
    @Override
    public ResponseResult queryLikesAndConllections(Integer wmUserId, Date beginDate, Date endDate) {
        return apArticleService.queryLikesAndConllections(wmUserId,beginDate,endDate);
    }

    @PostMapping("/api/v1/article/newPage")
    @Override
    public PageResponseResult newPage(StatisticsDto dto) {
        return apArticleService.newPage(dto);
    }

    @PostMapping("/pagecomment")
    @Override
    public PageResponseResult findNewsComments(@RequestBody CommentPageDto dto) {
        return apArticleService.findNewsComments(dto);
    }

    @GetMapping("/getconfig")
    public ResponseResult<ApArticleConfig> getConfig(Long articleId){
        return ResponseResult.okResult(apArticleConfigService.getOne(Wrappers.<ApArticleConfig>lambdaQuery()
                .eq(ApArticleConfig::getArticleId,articleId)));
    }

}
